package com.mvp.method2.base;

import android.os.Bundle;
import android.support.annotation.Nullable;

import com.mvp.method2.imvp.BasePresenter;
import com.mvp.method2.imvp.BaseView;

/**
 * Created by Administrator on 2019/3/6.
 */

public abstract class MVPActivity<P extends BasePresenter> extends BaseActivity implements BaseView {

    protected P mPresenter;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        if (mPresenter == null) {
            mPresenter = createPresenter();
        }
        if (mPresenter != null) {
            mPresenter.attachView(this);
        }
        super.onCreate(savedInstanceState);
    }

    protected abstract P createPresenter();

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (mPresenter != null) {
            mPresenter.detachView();
            mPresenter = null;
        }
    }

    public void showLoading() {
        showProgressDialog();
    }

    public void dismissLoading() {
        dissmissProgressDialog();
    }

}
